
/* 1.
 * Create a class rectangle. The class has attributes length and width,
 * each of which defaults to 1. It should have member functions that
 * calculate the perimeter and area of the rectangle. It should have set
 * and get functions for both length and width. The set functions should
 * verify that length and width are each floating-point numbers larger
 * than 0.0 and less than 20.0
 */

/* 2.
 * Modify the above class to include a draw function that displays a filled
 * rectangle using * as the default fill character. Include a setfillcharacter
 * function to specify the character out of which the body of the rectangle will
 * be drawn. Include a set setperimietercharacter function to specify the
 * character that will be used to draw the border of the rectangle.
 */

package classobject;

public class Rectangle {
	private float length, width;

	public Rectangle() {
		this.length = 1;
		this.width = 1;
	}

	public Rectangle(float length, float width) {
		this.length = length;
		this.width = width;
	}

	float calcPerimeter() {
		return 2 * (this.length + this.width);
	}

	public float getLength() {
		return length;
	}

	public float getWidth() {
		return width;
	}

	public void setLength(float length) {
		if (length < 0.0f)
			this.length = 0.0f;
		else if (length > 20.0f)
			this.length = 20.0f;
		else
			this.length = length;
	}

	public void setWidth(float width) {
		if (width < 0f)
			this.width = 0.0f;
		else if (width > 20.0f)
			this.width = 20.0f;
		else
			this.width = width;
	}

	void setFillCharacter(char c) {
		for (int i = 0; i < (int) this.length; i++) {
			for (int j = 0; j < (int) this.width; j++)
				System.out.print(c);
			System.out.println();
		}
	}

	void setPerimieterCharacter(char c) {
		for (int i = 0; i < (int) this.length; i++) {
			for (int j = 0; j < (int) this.width; j++)
				if (i == 0 || j == 0 || j == ((int) this.width - 1)
						|| i == ((int) this.length - 1))
					System.out.print(c);
				else
					System.out.print(' ');
			System.out.println();
		}
	}
}
